<template>
  <div>
    <div id="myChart"
         :style="{width: '100%', height: '550px'}"></div>
  </div>
</template>

<script>
  import ajax from '@/utils/baseurl'

  export default {
    name:"GoodsSat",
    data () {
      return {
      }
    },
    mounted(){
      this.drawLine();
    },
    methods: {
      drawLine(){
        // 基于准备好的dom，初始化echarts实例
        let myChart = this.$echarts.init(document.getElementById('myChart'));
        // 绘制图表
        myChart.setOption(
          {
            color: ['#3398DB'],
            tooltip : {
              trigger: 'axis',
              axisPointer : {            // 坐标轴指示器，坐标轴触发有效
                type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
              }
            },
            grid: {
              left: '3%',
              right: '4%',
              bottom: '3%',
              containLabel: true
            },
            xAxis : [
              {
                type : 'category',
                data : ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
                axisTick: {
                  alignWithLabel: true
                }
              }
            ],
            yAxis : [
              {
                type : 'value'
              }
            ],
            series : [
              {
                name:'库存',
                type:'bar',
                barWidth: '60%',
                data:[]
              }
            ]
          }
          );
        // 异步加载数据
        ajax("findInventory",{},function(data) {
          // console.log(data);
          // 填入数据
          myChart.setOption({
            series: [{
              data: data
            }]
          });
        });
        ajax("findproName",{},function(data) {
          console.log(data);
          // 填入数据
          myChart.setOption({
            xAxis : [
              {
                type : 'category',
                data : data,
                axisTick: {
                  alignWithLabel: true
                }
              }
            ],
          });
        });

      }
    }

  }
</script>
